package org.techmore.hakka;

import org.techmore.bussiness.QuestionsBeanDataHandler;
import org.techmore.common.utils.activity.ActivityUtils;
import org.techmore.common.utils.sound.SoundPoolUtils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;

public class AnswerResultActivity extends Activity {
	
	private TextView answer_result_judge = null;
	private TextView answer_result_result = null;
	private TextView answer_result_description = null;
	private ScrollView answer_result_description_scrollView = null;
	private Button answer_judge_button = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		ActivityUtils.getInstance().setScreenOrientation(this);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.answer_result);
		
		answer_result_judge = (TextView) findViewById(R.id.answer_result_judge);
		answer_result_result = (TextView) findViewById(R.id.answer_result_result);
		answer_result_description = (TextView) findViewById(R.id.answer_result_description);
		answer_result_description_scrollView = (ScrollView) findViewById(R.id.answer_result_description_scrollView);
		answer_judge_button = (Button) findViewById(R.id.answer_judge_button);
		
	}
	
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		
		int height = ActivityUtils.getInstance().getWidthHight(this)[1];
//		if(ActivityUtils.getInstance().getWidthHight(this)[1]>=ActivityUtils.getInstance().getWidthHight(this)[0]){
//			height = ActivityUtils.getInstance().getWidthHight(this)[1];
//		}else{
//			height = ActivityUtils.getInstance().getWidthHight(this)[0];
//		}
		
		LayoutParams params = answer_result_description_scrollView.getLayoutParams();
		params.height = height-answer_result_judge.getLayoutParams().height-answer_result_result.getLayoutParams().height
						-answer_judge_button.getLayoutParams().height-30-40;
		
		Intent intent = getIntent();
		if(intent.getBooleanExtra("results", false)){
			answer_result_judge.setText(R.string.answer_result_judge_true);
		}else{
			answer_result_judge.setText(R.string.answer_result_judge_false);
		}
		answer_result_result.setText(intent.getStringExtra("trueAnswer"));
		answer_result_description.setText(intent.getStringExtra("description"));
		
		answer_judge_button.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				int k = QuestionsBeanDataHandler.getInstance().increaseQuestionIndex();
				SoundPoolUtils.getInstance(AnswerResultActivity.this).playSound(SoundPoolUtils.SOUND_BUTTON_CLICK);
				if(k==-1){
					ActivityUtils.getInstance().leftIN_rightOUT_close_Transition(AnswerResultActivity.this, AnswerResultActivity.this, AnswerQuestionActivity.class);
				}else if(k==-2){
					ActivityUtils.getInstance().leftIN_rightOUT_close_Transition(AnswerResultActivity.this, AnswerResultActivity.this, QuestionResultActivity.class);
				}else{
					
				}
				
			}
		});
	}

}
